package com.foxnicweb.app.patent.role;

import com.foxnicweb.app.constants.enums.patent.ProcessRoleType;
import com.foxnicweb.app.domain.patent.PatentProcessRole;
import com.foxnicweb.app.domain.patent.meta.PatentProcessRoleMeta;
import com.foxnicweb.app.patent.service.IPatentProcessRoleService;
import com.github.foxnic.commons.collection.CollectorUtil;
import com.github.foxnic.commons.lang.DataParser;
import org.github.foxnic.web.domain.hrm.Employee;
import org.github.foxnic.web.framework.busi.role.BusiRoleMemberRouter;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public abstract class ProcessRole implements BusiRoleMemberRouter {

    @Autowired
    protected IPatentProcessRoleService roleService;

    private ProcessRoleType roleType = null;

    public ProcessRoleType getRoleType() {
        return roleType;
    }

    public ProcessRole(ProcessRoleType roleType) {
        this.roleType = roleType;
    }

    @Override
    public List<Employee> getMembers(Context context) {

        Long patentProcessId = DataParser.parseLong(context.getBillIds().get(0));
        PatentProcessRole sample = new PatentProcessRole();
        sample.setPatentProcessId(patentProcessId);
        sample.setRoleType(this.getRoleType().code());
        List<PatentProcessRole> roles= roleService.queryList(sample);
        roleService.join(roles, PatentProcessRoleMeta.EMPLOYEE);
        List<Employee> employees= CollectorUtil.collectList(roles,PatentProcessRole::getEmployee);
        return employees;
    }


}
